package testes.vSys.action;

import java.util.Collection;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import testes.vSys.bean.Vehicle;
import testes.vSys.dao.DAOFactory;
import testes.vSys.dao.IVehicleDao;
import testes.vSys.form.VehiclesFinancesReportForm;

public class VehiclesFinancesReportAction extends DispatchAction{

	private final String VEHICLES_COLLECTION = "vehiclesCollection";
	private String optionDisplay = "model"; 
	
	public ActionForward load(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		IVehicleDao vehicleDAO = DAOFactory.getVehicleDao();
		
		Collection<Vehicle> vehicles = vehicleDAO.getVehicles(this.optionDisplay);
		
		request.setAttribute(VEHICLES_COLLECTION, vehicles);

		return mapping.findForward("vehiclesFinancesReport");
	}
	
	public ActionForward searchByModel(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {

		VehiclesFinancesReportForm vehicleForm = (VehiclesFinancesReportForm)form;
		
		System.out.println(vehicleForm.getOpr());
		
		this.optionDisplay = vehicleForm.getSelectedType();
		
		return load(mapping, form, request, response);
	}
	
}